import AMapLoader from "@amap/amap-jsapi-loader"
window._AMapSecurityConfig = {
  securityJsCode: 'c342b35e47ac62df522f4aa5c2b7be4b',
}
export function initMap(plugins=[],uiPlugins=[]) {
  let mapPlugins = [...new Set([...[
    'AMap.ToolBar',
    'AMap.Driving',
    'AMap.PolygonEditor',
    'AMap.DragRoute',
    'AMap.MouseTool'
  ],...plugins])]
  let uiMapPlugins = [...new Set([...["misc/PoiPicker"],...uiPlugins])]
  return new Promise((resolve, reject) => {
    if (window.AMap) {
      console.log("高德地图已经加载过了");
      resolve(window.AMap);
    } else {
      console.log("加载高德地图");
      AMapLoader.load({
        key: "87c700ab83b84c83ab7fe1f3c852a1c0", // 申请好的Web端开发者Key，首次调用 load 时必填
        version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
        plugins: mapPlugins, // 需要使用的的插件列表，如比例尺'AMap.Scale'等
        AMapUI: {
          // 是否加载 AMapUI，缺省不加载
          version: "1.1", // AMapUI 缺省 1.1
          plugins: uiMapPlugins, // 需要加载的 AMapUI ui插件
        },
        Loca: {
          version: "2.0.0"
        },
      }).then((AMap) => {
        resolve(AMap);
      }).catch((e) => {
        reject(e);
      })
    }
    // console.log(window);
  })
}


/*export function initMap() {
    return AMapLoader.load({
        key: '87c700ab83b84c83ab7fe1f3c852a1c0',  //设置您的key
        version: "2.0",
        plugins: [
          'AMap.ToolBar', 
          'AMap.Driving',
          'AMap.PolygonEditor',
          'AMap.DragRoute'
        ],
        AMapUI: {
          version: "1.1",
          plugins: ["misc/PoiPicker"],
        },
        Loca: {
          version: "2.0.0"
        },
      })
}*/
